﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace IntegratedOnBordDebug
{
    public class InfoPacket
    {
        ProtocolHead ppHead = new ProtocolHead();
        public ProtocolHead head
        {
            get
            {
                return ppHead;
            }
            set
            {
                ppHead = value;
            }
        }

        private Dictionary<string, object> ppBody = null;
        public Dictionary<string, object> body
        {
            get
            {
                return ppBody;
            }
            set
            {
                if (ppBody == null)
                    ppBody = new Dictionary<string, object>();
                ppBody = value;
            }
        }

        /// <summary>十六进制字符串数组转换成byte数组
        /// 
        /// </summary>
        /// <param name="planArray">十六进制字符串数组</param>
        /// <returns></returns>
        public static byte[] parseByteFromHexString(string[] planArray)
        {
            if (planArray.Length == 0)
                return null;

            byte[] result = new byte[planArray.Length];
            for (int i = 0; i < planArray.Length; i++)
            {
                result[i] = (byte)Convert.ToInt32(planArray[i], 16);
            }
            return result;
        }

        /// <summary>整型字符串数组转换成byte数组
        /// 
        /// </summary>
        /// <param name="planArray">整型字符串数组</param>
        /// <returns></returns>
        public static byte[] parseByteFromString(string[] planArray)
        {
            if (planArray.Length == 0)
                return null;

            byte[] result = new byte[planArray.Length];
            for (int i = 0; i < planArray.Length; i++)
            {
                result[i] = Convert.ToByte(planArray[i]);
            }
            return result;
        }

        /// <summary>
        /// MAC字符串数组转换成byte数组
        /// </summary>
        /// <param name="planArray">整型字符串数组</param>
        /// <returns></returns>
        public static byte[] parseByteFromMACString(string[] planArray)
        {
            if (planArray.Length == 0)
                return null;

            byte[] result = new byte[planArray.Length];
            for (int i = 0; i < planArray.Length; i++)
            {
                result[i] = (byte)Convert.ToInt32(planArray[i], 16);
            }
            return result;
        }

        /// <summary>
        /// 创建日期时间格式命令
        /// </summary>
        /// <param name="dtFormat">
        /// 格式代码：
        /// 0 yy年MM月dd日；
        /// 1 yy-MM-dd；
        /// 2 yy/MM/dd；
        /// 3 yy.MM.dd；
        /// 4 HH时mm分ss秒 (24H)
        /// 5 H时mm分ss秒 (12H)
        /// 6 HH:mm:ss (24H)
        /// 7 H:mm:ss (12H)
        /// 8 yyyy年MM月dd日 HH时mm分ss秒 (24H)
        /// 9 yyyy年MM月dd日 HH时mm分ss秒 (12H)
        /// 10 yyyy-MM-dd HH-mm-ss (24H)
        /// 11 yyyy-MM-dd HH-mm-ss (12H)
        /// </param>
        /// <returns></returns>
        public static byte[] createCMDDateTime(int dtFormat = 0)
        {
            //*时*分*秒
            byte[] list = null;
            byte[] yy = Encoding.Default.GetBytes(DateTime.Now.ToString("yyyy").Substring(0, 2));
            int idx = 0;
            switch (dtFormat)
            {
                default:
                case 0: //yy年MM月dd日
                    list = new byte[12 + yy.Length];
                    yy.CopyTo(list, idx);
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("年").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("月").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x13;
                    Encoding.Default.GetBytes("日").CopyTo(list, ++idx + yy.Length);
                    break;
                case 1: //yy-MM-dd
                    list = new byte[8 + yy.Length];
                    yy.CopyTo(list, 0);
                    list[0 + yy.Length] = 0x10;
                    list[1 + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("-").CopyTo(list, 2 + yy.Length);
                    list[3 + yy.Length] = 0x10;
                    list[4 + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("-").CopyTo(list, 5 + yy.Length);
                    list[6 + yy.Length] = 0x10;
                    list[7 + yy.Length] = 0x13;
                    break;
                case 2: //yy/MM/dd
                    list = new byte[8 + yy.Length];
                    yy.CopyTo(list, 0);
                    list[0 + yy.Length] = 0x10;
                    list[1 + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("/").CopyTo(list, 2 + yy.Length);
                    list[3 + yy.Length] = 0x10;
                    list[4 + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("/").CopyTo(list, 5 + yy.Length);
                    list[6 + yy.Length] = 0x10;
                    list[7 + yy.Length] = 0x13;
                    break;
                case 3: //yy.MM.dd
                    list = new byte[8];
                    yy.CopyTo(list, 0);
                    list[0 + yy.Length] = 0x10;
                    list[1 + yy.Length] = 0x11;
                    Encoding.Default.GetBytes(".").CopyTo(list, 2 + yy.Length);
                    list[3 + yy.Length] = 0x10;
                    list[4 + yy.Length] = 0x12;
                    Encoding.Default.GetBytes(".").CopyTo(list, 5 + yy.Length);
                    list[6 + yy.Length] = 0x10;
                    list[7 + yy.Length] = 0x13;
                    break;
                case 4: // HH时mm分ss秒 24小时
                    list = new byte[12];
                    list[0] = 0x10;
                    list[1] = 0x16; //时(24H制)
                    Encoding.Default.GetBytes("时").CopyTo(list, 2);
                    list[4] = 0x10;
                    list[5] = 0x17;
                    Encoding.Default.GetBytes("分").CopyTo(list, 6);
                    list[8] = 0x10;
                    list[9] = 0x18;
                    Encoding.Default.GetBytes("秒").CopyTo(list, 10);
                    break;
                case 5: // H时mm分ss秒 12小时
                    list = new byte[12];
                    list[0] = 0x10;
                    list[1] = 0x15; //时(12H制)
                    Encoding.Default.GetBytes("时").CopyTo(list, 2);
                    list[4] = 0x10;
                    list[5] = 0x17;
                    Encoding.Default.GetBytes("分").CopyTo(list, 6);
                    list[8] = 0x10;
                    list[9] = 0x18;
                    Encoding.Default.GetBytes("秒").CopyTo(list, 10);
                    break;
                case 6: // HH:mm:ss (24H制)
                    list = new byte[8];
                    list[0] = 0x10;
                    list[1] = 0x16; //时(24H制)
                    list[2] = 0x3A; //":"
                    list[3] = 0x10;
                    list[4] = 0x17;
                    list[5] = 0x3A; //":"
                    list[6] = 0x10;
                    list[7] = 0x18;
                    break;
                case 7: // H:mm:ss (12H制)
                    list = new byte[8];
                    list[0] = 0x10;
                    list[1] = 0x15; //时(12H制)
                    list[2] = 0x3A; //":"
                    list[3] = 0x10;
                    list[4] = 0x17;
                    list[5] = 0x3A; //":"
                    list[6] = 0x10;
                    list[7] = 0x18;
                    break;
                case 8:     //yyyy年MM月dd日 HH时mm分ss秒
                    list = new byte[25 + yy.Length];
                    yy.CopyTo(list, idx);
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("年").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("月").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x13;
                    Encoding.Default.GetBytes("日").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x20; //空格                    
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x16; //时(24H制)
                    Encoding.Default.GetBytes("时").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x17;
                    Encoding.Default.GetBytes("分").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x18;
                    Encoding.Default.GetBytes("秒").CopyTo(list, ++idx + yy.Length);
                    break;
                case 9:     //yy年MM月dd日 H时mm分ss秒
                    list = new byte[25 + yy.Length];
                    yy.CopyTo(list, idx);
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("年").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("月").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x13;
                    Encoding.Default.GetBytes("日").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x20; //空格  
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x15; //时(12H制)
                    Encoding.Default.GetBytes("时").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x17;
                    Encoding.Default.GetBytes("分").CopyTo(list, ++idx + yy.Length);
                    idx += 2;
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x18;
                    Encoding.Default.GetBytes("秒").CopyTo(list, ++idx + yy.Length);
                    break;
                case 10:    //yy-MM-dd HH:mm:ss
                    list = new byte[17 + yy.Length];
                    yy.CopyTo(list, idx);
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("-").CopyTo(list, ++idx + yy.Length);
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("-").CopyTo(list, ++idx + yy.Length);
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x13;
                    list[++idx + yy.Length] = 0x20;  //空格
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x16; //时(24H制)
                    list[++idx + yy.Length] = 0x3A; //":"
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x17;
                    list[++idx + yy.Length] = 0x3A; //":"
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x18;
                    break;
                case 11:    //yy-MM-dd H:mm:ss
                    list = new byte[17 + yy.Length];
                    yy.CopyTo(list, idx);
                    list[idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x11;
                    Encoding.Default.GetBytes("-").CopyTo(list, ++idx + yy.Length);
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x12;
                    Encoding.Default.GetBytes("-").CopyTo(list, ++idx + yy.Length);
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x13;
                    list[++idx + yy.Length] = 0x20;  //空格
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x15; //时(12H制)
                    list[++idx + yy.Length] = 0x3A; //":"
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x17;
                    list[++idx + yy.Length] = 0x3A; //":"
                    list[++idx + yy.Length] = 0x10;
                    list[++idx + yy.Length] = 0x18;
                    break;
            }
            return list.ToArray();
        }

        //显示屏使用之函数
        //public static byte FloatToBuf(float dataValue)
        //{
        //    List<byte> buf = new List<byte>();
        //    uint music_data;
        //    byte[] dataBuf = new byte[30];
        //    byte cnt;
        //    music_data = (uint)(dataValue * 10);
        //    music_data = music_data % 1000; //最高位
        //    cnt = 0;
        //    dataBuf[cnt] = (byte)(music_data / 100000);
        //    if (dataBuf[cnt] != 0)
        //    {
        //        cnt++;
        //        dataBuf[cnt++] = (byte)(1000);
        //    }
        //    music_data = music_data % 100000;
        //    dataBuf[cnt] = music_data / 10000;
        //    if (dataBuf[cnt] != 0)
        //    {
        //        cnt++;
        //        dataBuf[cnt++] = SPEECH_HUNDRED;
        //    }
        //    music_data = music_data % 10000;
        //    dataBuf[cnt] = music_data / 1000;
        //    if (dataBuf[cnt] != 0)
        //    {
        //        cnt++;
        //        dataBuf[cnt++] = SPEECH_TEN;
        //    }
        //    music_data = music_data % 1000;
        //    dataBuf[cnt] = music_data / 100;
        //    if (dataBuf[cnt] != 0)
        //    {
        //        cnt++;

        //    }
        //    music_data = music_data % 100;
        //    if (music_data != 0)
        //    {
        //        dataBuf[cnt++] = SPEECH_DOT;
        //        dataBuf[cnt++] = music_data / 10;
        //        music_data = music_data % 10;
        //        dataBuf[cnt++] = music_data / 1;
        //    }
        //    memcpy(buf, dataBuf, cnt);
        //    if (cnt == 0)
        //    {
        //        cnt = 1;
        //        *buf = 0;
        //    }
        //    return cnt;
        //}

        public static byte[] ModelToByte(InfoPacket packet)
        {
            byte[] result1;
            byte[] buff = new byte[22];
            byte[] head = new byte[32];
            byte[] tmpBytes;
            bool hasBody = false;
            int idx = 0;
            string uIpv4Addr = string.Empty;
            string uIpv4Mask = string.Empty;
            string uIpv4Gateway = string.Empty;
            string byMac = string.Empty;
            byte[] tmpMsg = Encoding.Default.GetBytes(new string(' ', 48));    //空格填充默认信息

            BitConverter.GetBytes(packet.head.uVersion).CopyTo(head, 4 * 0);
            BitConverter.GetBytes(packet.head.uCommandID).CopyTo(head, 4 * 1);
            BitConverter.GetBytes(packet.head.uSessionID).CopyTo(head, 4 * 2);
            BitConverter.GetBytes(Convert.ToInt16(packet.head.uDataLength)).CopyTo(head, 4 * 3);
            BitConverter.GetBytes(packet.head.uErrorCode).CopyTo(head, 4 * 4);
            new UTF8Encoding().GetBytes(packet.head.szReserved).CopyTo(head, 4 * 5);
            BitConverter.GetBytes(packet.head.uCheckSum).CopyTo(head, 4 * 5 + 8);
            if (packet.body != null && packet.body.Count > 0)
            {
                switch (packet.head.uCommandID)
                {                    
                    case 0x0061:    //扩展设备消息订阅
                        hasBody = true;
                        buff = new byte[6];
                        uIpv4Addr = packet.body["uIpv4Addr"].ToString();    //订阅者IP
                        tmpBytes = parseByteFromString(uIpv4Addr.Split('.'));
                        buff[idx] = tmpBytes[0];
                        buff[++idx] = tmpBytes[1];
                        buff[++idx] = tmpBytes[2];
                        buff[++idx] = tmpBytes[3];
                        ushort port = Convert.ToUInt16(packet.body["uPort"]); //订阅者端口
                        tmpBytes = BitConverter.GetBytes(port).Reverse().ToArray();
                        buff[++idx] = tmpBytes[0];
                        buff[++idx] = tmpBytes[1];
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0043:
                        hasBody = true;
                        buff = new byte[11];

                        buff[idx] = 0x7B;   //引导码 固定
                        buff[++idx] = 0x53; //识别符 固定
                        string ledId = Convert.ToUInt32(packet.body["LedId"]).ToString().PadLeft(2, '0');
                        tmpBytes = Encoding.ASCII.GetBytes(ledId);
                        buff[++idx] = tmpBytes[0];     //地址H
                        buff[++idx] = tmpBytes[1];    //地址L
                        tmpBytes = Encoding.ASCII.GetBytes(packet.body["LedColor"].ToString());
                        buff[++idx] = tmpBytes[0];   //数字颜色 范围0至30 - 红色，1 - 绿色，2 - 黄色，3 - 自动（内容为0时红色，不为0时绿色）
                        tmpBytes = Encoding.ASCII.GetBytes(packet.body["GuidWay"].ToString());
                        buff[++idx] = tmpBytes[0];    //围0至7 箭头在数字后: 0 - 右,1 - 上，2 - 左，3 - 下 箭头在数字前: 4 - 右,5 - 上，6 - 左，7 - 下
                        string showNum = Convert.ToUInt32(packet.body["ShowNum"]).ToString().PadLeft(4, '0'); //显示内容 总车位数、剩余车位数
                        tmpBytes = Encoding.ASCII.GetBytes(showNum);
                        buff[++idx] = tmpBytes[0];
                        buff[++idx] = tmpBytes[1];
                        buff[++idx] = tmpBytes[2];
                        buff[++idx] = tmpBytes[3];
                        buff[++idx] = 0x7D; //结束码 固定
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0042: //远程程序更新
                        hasBody = true;
                        buff = BitConverter.GetBytes(Convert.ToUInt32(packet.body["ProgramLength"])); //bin 文件程序字节数
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0041:    //程序远程下载
                    case 0x0040:    //下载字库
                        hasBody = true;
                        buff = new byte[264];
                        uint bagTotal = Convert.ToUInt32(packet.body["bagTotal"]);    //包总数 0
                        uint bagNum = Convert.ToUInt32(packet.body["bagNum"]);    //当前包索引
                        tmpBytes = (byte[])packet.body["bagBuff"];                  //当前包字库数据

                        BitConverter.GetBytes(bagTotal).CopyTo(buff, 0);
                        BitConverter.GetBytes(bagNum).CopyTo(buff, 4);
                        tmpBytes.CopyTo(buff, 8);

                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0003:    //广播修改IP
                        hasBody = true;
                        buff = new byte[28];
                        uIpv4Addr = packet.body["uIpv4Addr"].ToString();
                        uIpv4Mask = packet.body["uIpv4Mask"].ToString();
                        uIpv4Gateway = packet.body["uIpv4Gateway"].ToString();
                        byMac = packet.body["byMac"].ToString();
                        tmpBytes = parseByteFromString(uIpv4Addr.Split('.')).Reverse().ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        idx += 4;
                        tmpBytes = parseByteFromString(uIpv4Mask.Split('.')).Reverse().ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        idx += 4;
                        tmpBytes = parseByteFromString(uIpv4Gateway.Split('.')).Reverse().ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        idx += 4;
                        tmpBytes = parseByteFromMACString(byMac.Split(':')).ToArray();
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x000D:    //设置网络
                        hasBody = true;
                        buff = new byte[26];
                        uIpv4Addr = packet.body["uIpv4Addr"].ToString();
                        uIpv4Mask = packet.body["uIpv4Mask"].ToString();
                        uIpv4Gateway = packet.body["uIpv4Gateway"].ToString();
                        byMac = packet.body["byMac"].ToString();
                        tmpBytes = parseByteFromString(uIpv4Addr.Split('.')).Reverse().ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        idx += 4;
                        tmpBytes = parseByteFromString(uIpv4Mask.Split('.')).Reverse().ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        idx += 4;
                        tmpBytes = parseByteFromString(uIpv4Gateway.Split('.')).Reverse().ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        idx += 4;
                        tmpBytes = parseByteFromMACString(byMac.Split(':')).ToArray();
                        tmpBytes.CopyTo(buff, idx);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);

                        break;
                    case 0x0011:    //设置485串口信息
                        hasBody = true;
                        buff = new byte[1];
                        buff[0] = Convert.ToByte(packet.body["uSpeed"]);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0037:    //设置补光灯开启和关闭时间
                        hasBody = true;
                        buff = new byte[5];
                        buff[0] = Convert.ToByte(packet.body["EnableLight"]);
                        buff[1] = Convert.ToByte(packet.body["HourOn"]);
                        buff[2] = Convert.ToByte(packet.body["MinuteOn"]);
                        buff[3] = Convert.ToByte(packet.body["HourOff"]);
                        buff[4] = Convert.ToByte(packet.body["MinuteOff"]);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x000F:    //校时
                        hasBody = true;
                        buff = new byte[6];
                        buff[0] = Convert.ToByte(packet.body["pYear"]);
                        buff[1] = Convert.ToByte(packet.body["pMonth"]);
                        buff[2] = Convert.ToByte(packet.body["pDay"]);
                        buff[3] = Convert.ToByte(packet.body["pHour"]);
                        buff[4] = Convert.ToByte(packet.body["pMinute"]);
                        buff[5] = Convert.ToByte(packet.body["pSecond"]);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0033:    //设置LED显示信息
                        hasBody = true;
                        /* uCommand 值类型： 00-查询屏幕类型 01-设置屏幕类型 02-发布显示内容 03-发布默认显示内容（断电保存） 04-发布默认显示内容（断电不保存） */
                        int cmdShowWay = Convert.ToInt32(packet.body["uCommand"]);
                        if (cmdShowWay == 0)
                        {
                            buff = new byte[1];
                            buff[0] = Convert.ToByte(packet.body["uCommand"]);
                            packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                            BitConverter.GetBytes(Convert.ToInt16(packet.head.uDataLength)).CopyTo(head, 4 * 3);
                            break;
                        }
                        else if (cmdShowWay == 1) //设置Led屏类型
                        {
                            buff = new byte[4];
                            BitConverter.GetBytes(Convert.ToByte(packet.body["uCommand"])).CopyTo(buff, 0);
                            BitConverter.GetBytes(Convert.ToByte(packet.body["uSelectedIndex"])).CopyTo(buff, 1);

                            packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                            BitConverter.GetBytes(Convert.ToInt16(packet.head.uDataLength)).CopyTo(head, 4 * 3);
                        }
                        else if (cmdShowWay == 2 || cmdShowWay == 3 || cmdShowWay == 4)//设置默认值
                        {
                            //对应行屏数
                            int msgScreenSum1 = 0, msgScreenSum2 = 0, msgScreenSum3 = 0, msgScreenSum4 = 0;
                            int showTime = 0;       //是否显示时间
                            int showTimePos = 0;    //时间显示位置
                            int showTimeFormat = 0; //时间格式
                            int msgLen = 0;   //内容计算之后长度
                            InfoEnumClass.EmControllerLedType ctrlLedType = (InfoEnumClass.EmControllerLedType)Enum.Parse(typeof(InfoEnumClass.EmControllerLedType),packet.body["uSelectedIndex"].ToString());
                            
                            switch (ctrlLedType) //led 屏幕类型
                            {
                                case InfoEnumClass.EmControllerLedType.Led_16_32://一行

                                    byte[] byteMsg1 = Encoding.Default.GetBytes(packet.body["uLedMsg"].ToString());

                                    buff = new byte[56];
                                    BitConverter.GetBytes(Convert.ToByte(packet.body["uCommand"])).CopyTo(buff, 0);
                                    BitConverter.GetBytes(Convert.ToByte(packet.body["uSelectedIndex"])).CopyTo(buff, 1);
                                    buff[2] = Convert.ToByte(packet.body["uKeepTime"]); //发布的内容保持时间范围0~255，单位秒，超时之后恢复默认显示；等于0时，表示内容保持时间无限长；
                                    //保留字段占一字节buff[7]

                                    //第一行
                                    buff[4] = Convert.ToByte(packet.body["uLineNumber"]);
                                    buff[6] = Convert.ToByte(packet.body["OneEffect"]);//特效全部为0-静态多屏切换显示; 1-静态显示，2-左移
                                    buff[7] = Convert.ToByte(packet.body["uLedChangeTime"]);//多屏显示切换时间，单位秒，范围1至60
                                    tmpMsg.CopyTo(buff, 8);

                                    showTime = Convert.ToInt32(packet.body["OneShowTime"]);
                                    showTimePos = Convert.ToInt32(packet.body["OneTimePos"]);
                                    showTimeFormat = Convert.ToInt32(packet.body["OneTimeFormat"]);
                                    msgLen = SetMessageToBuff(byteMsg1, 8, showTime, showTimePos, showTimeFormat, ref buff);

                                    msgScreenSum1 = (int)Math.Ceiling(msgLen / 8.0);    //计算屏数,最多6屏
                                    msgScreenSum1 = msgScreenSum1 > 6 ? 6 : msgScreenSum1;
                                    buff[5] = Convert.ToByte(msgScreenSum1); //设置屏数

                                    packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                                    BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                                    break;
                                case InfoEnumClass.EmControllerLedType.Led_32_64://两行

                                    byte[] byteMsg2 = Encoding.Default.GetBytes(packet.body["uLedMsg"].ToString());
                                    byte[] byteMsg3 = Encoding.Default.GetBytes(packet.body["uLedMsg2"].ToString());
                                    int Length;

                                    buff = new byte[4 + 52 * 2];    //计算数据总长度
                                    Length = 48;

                                    BitConverter.GetBytes(Convert.ToByte(packet.body["uCommand"])).CopyTo(buff, 0);
                                    BitConverter.GetBytes(Convert.ToByte(packet.body["uSelectedIndex"])).CopyTo(buff, 1);
                                    buff[2] = Convert.ToByte(packet.body["uKeepTime"]);
                                    //保留字段占一字节buff[3]

                                    //第一行
                                    buff[4] = Convert.ToByte(packet.body["uLineNumber"]);
                                    buff[6] = Convert.ToByte(packet.body["OneEffect"]);//特效全部为0-静态多屏切换显示;
                                    buff[7] = Convert.ToByte(packet.body["uLedChangeTime"]);

                                    tmpMsg.CopyTo(buff, 8);
                                    showTime = Convert.ToInt32(packet.body["OneShowTime"]);
                                    showTimePos = Convert.ToInt32(packet.body["OneTimePos"]);
                                    showTimeFormat = Convert.ToInt32(packet.body["OneTimeFormat"]);
                                    msgLen = SetMessageToBuff(byteMsg2, 8, showTime, showTimePos, showTimeFormat, ref buff);

                                    //计算屏数,最多6屏
                                    msgScreenSum1 = (int)Math.Ceiling(msgLen / 8.0);
                                    msgScreenSum1 = msgScreenSum1 > 6 ? 6 : msgScreenSum1;
                                    buff[5] = Convert.ToByte(msgScreenSum1); //设置屏数

                                    //第二行
                                    buff[8 + Length] = Convert.ToByte(packet.body["uLineNumber2"]);
                                    buff[10 + Length] = Convert.ToByte(packet.body["TwoEffect"]);//特效全部为0-静态多屏切换显示;
                                    buff[11 + Length] = Convert.ToByte(packet.body["uLedChangeTime2"]);

                                    tmpMsg.CopyTo(buff, 12 + Length);
                                    showTime = Convert.ToInt32(packet.body["TwoShowTime"]);
                                    showTimePos = Convert.ToInt32(packet.body["TwoTimePos"]);
                                    showTimeFormat = Convert.ToInt32(packet.body["TwoTimeFormat"]);
                                    msgLen = SetMessageToBuff(byteMsg3, 12 + Length, showTime, showTimePos, showTimeFormat, ref buff);

                                    //计算屏数,最多6屏
                                    msgScreenSum2 = (int)Math.Ceiling(msgLen / 8.0);
                                    msgScreenSum2 = msgScreenSum2 > 6 ? 6 : msgScreenSum2;
                                    buff[9 + Length] = Convert.ToByte(msgScreenSum2); //设置屏数

                                    packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                                    BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                                    break;
                                case InfoEnumClass.EmControllerLedType.Led_32_128: //32*128保留

                                    break;
                                case InfoEnumClass.EmControllerLedType.Led_64_128://四行 64*128点阵屏
                                    int threeFourBind = Convert.ToInt32(packet.body["ThreeFourBind"]);

                                    byte[] byteMsg4 = Encoding.Default.GetBytes(packet.body["uLedMsg"].ToString());
                                    byte[] byteMsg5 = Encoding.Default.GetBytes(packet.body["uLedMsg2"].ToString());
                                    byte[] byteMsg6 = Encoding.Default.GetBytes(packet.body["uLedMsg3"].ToString());
                                    byte[] byteMsg7 = Encoding.Default.GetBytes(packet.body["uLedMsg4"].ToString());

                                    buff = new byte[4 + 52 * 4];    //计算数据总长度
                                    BitConverter.GetBytes(Convert.ToByte(packet.body["uCommand"])).CopyTo(buff, 0);
                                    BitConverter.GetBytes(Convert.ToByte(packet.body["uSelectedIndex"])).CopyTo(buff, 1);
                                    buff[2] = Convert.ToByte(packet.body["uKeepTime"]);
                                    //保留字段占一字节buff[3]

                                    //第一行
                                    buff[4] = Convert.ToByte(packet.body["uLineNumber"]);
                                    buff[6] = Convert.ToByte(packet.body["OneEffect"]);//特效 0-静态多屏切换；2-左移；3-静态左移(仅适用于屏类型64*128)
                                    buff[7] = Convert.ToByte(packet.body["uLedChangeTime"]);
                                    tmpMsg.CopyTo(buff, 8);

                                    showTime = Convert.ToInt32(packet.body["OneShowTime"]);
                                    showTimePos = Convert.ToInt32(packet.body["OneTimePos"]);
                                    showTimeFormat = Convert.ToInt32(packet.body["OneTimeFormat"]);
                                    msgLen = SetMessageToBuff(byteMsg4, 8, showTime, showTimePos, showTimeFormat, ref buff);

                                    //计算屏数,最多3屏,每屏16字节长度
                                    msgScreenSum1 = (int)Math.Ceiling(msgLen / 16.0);
                                    msgScreenSum1 = msgScreenSum1 > 3 ? 3 : msgScreenSum1;
                                    buff[5] = Convert.ToByte(msgScreenSum1); //设置屏数

                                    //第二行
                                    buff[0 + 56] = Convert.ToByte(packet.body["uLineNumber2"]);
                                    buff[2 + 56] = Convert.ToByte(packet.body["TwoEffect"]);//特效全部为0-静态多屏切换显示;
                                    buff[3 + 56] = Convert.ToByte(packet.body["uLedChangeTime2"]);
                                    tmpMsg.CopyTo(buff, 4 + 56);

                                    showTime = Convert.ToInt32(packet.body["TwoShowTime"]);
                                    showTimePos = Convert.ToInt32(packet.body["TwoTimePos"]);
                                    showTimeFormat = Convert.ToInt32(packet.body["TwoTimeFormat"]);
                                    msgLen = SetMessageToBuff(byteMsg5, 4 + 56, showTime, showTimePos, showTimeFormat, ref buff);

                                    //计算屏数,最多3屏,每屏16字节长度
                                    msgScreenSum2 = (int)Math.Ceiling(msgLen / 16.0);
                                    msgScreenSum2 = msgScreenSum2 > 3 ? 3 : msgScreenSum2;
                                    buff[1 + 56] = Convert.ToByte(msgScreenSum2); //设置屏数

                                    /*第三第四行合并一行显示，
                                        0 分行（默认） 
                                        1 分行显示日期及时间；
                                        2 金额:****元（并行）；
                                        3 余:****天（并行）；
                                        4 余:****元（并行）；
                                        5 余:****位（并行）*/
                                    switch (threeFourBind)
                                    {
                                        default:
                                        case 0: //分行显示

                                            //第③行
                                            buff[0 + 108] = Convert.ToByte(packet.body["uLineNumber3"]);
                                            buff[2 + 108] = Convert.ToByte(packet.body["ThreeEffect"]);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 108] = Convert.ToByte(packet.body["uLedChangeTime3"]);

                                            tmpMsg.CopyTo(buff, 4 + 108);

                                            showTime = Convert.ToInt32(packet.body["ThreeShowTime"]);
                                            showTimePos = Convert.ToInt32(packet.body["ThreeTimePos"]);
                                            showTimeFormat = Convert.ToInt32(packet.body["ThreeTimeFormat"]);
                                            msgLen = SetMessageToBuff(byteMsg6, 4 + 108, showTime, showTimePos, showTimeFormat, ref buff);

                                            //计算屏数,最多3屏,每屏16字节长度
                                            msgScreenSum3 = (int)Math.Ceiling(msgLen / 16.0);
                                            msgScreenSum3 = msgScreenSum3 > 3 ? 3 : msgScreenSum3;
                                            buff[1 + 108] = Convert.ToByte(msgScreenSum3); //设置屏数

                                            //第④行
                                            buff[0 + 160] = Convert.ToByte(packet.body["uLineNumber4"]);
                                            buff[1 + 160] = Convert.ToByte(packet.body["uLedScreenSum4"]);
                                            buff[2 + 160] = Convert.ToByte(packet.body["FourEffect"]);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 160] = Convert.ToByte(packet.body["uLedChangeTime4"]);
                                            tmpMsg.CopyTo(buff, 4 + 160);

                                            showTime = Convert.ToInt32(packet.body["FourShowTime"]);
                                            showTimePos = Convert.ToInt32(packet.body["FourTimePos"]);
                                            showTimeFormat = Convert.ToInt32(packet.body["FourTimeFormat"]);
                                            msgLen = SetMessageToBuff(byteMsg7, 4 + 160, showTime, showTimePos, showTimeFormat, ref buff);

                                            //计算屏数,最多3屏,每屏16字节长度
                                            msgScreenSum4 = (int)Math.Ceiling(msgLen / 16.0);
                                            msgScreenSum4 = msgScreenSum4 > 3 ? 3 : msgScreenSum4;
                                            buff[1 + 160] = Convert.ToByte(msgScreenSum4); //设置屏数

                                            break;
                                        case 1: // 显示当前日期时间 （内容只有8字节）
                                            //第③行 显示年月日
                                            packet.body["uLedScreenSum3"] = 1;
                                            buff[0 + 108] = Convert.ToByte(packet.body["uLineNumber3"]);
                                            buff[1 + 108] = Convert.ToByte(packet.body["uLedScreenSum3"]);
                                            buff[2 + 108] = Convert.ToByte(0);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 108] = Convert.ToByte(packet.body["uLedChangeTime3"]);
                                            tmpMsg.CopyTo(buff, 4 + 108);
                                            createCMDDateTime(0).CopyTo(buff, 4 + 108); //插入 yy年MM月dd日

                                            //第④行 显示时分秒
                                            packet.body["uLedScreenSum4"] = 1;
                                            buff[0 + 160] = Convert.ToByte(packet.body["uLineNumber4"]);
                                            buff[1 + 160] = Convert.ToByte(packet.body["uLedScreenSum4"]);
                                            buff[2 + 160] = Convert.ToByte(0);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 160] = Convert.ToByte(packet.body["uLedChangeTime4"]);
                                            tmpMsg.CopyTo(buff, 4 + 160);
                                            createCMDDateTime(0).CopyTo(buff, 4 + 160);
                                            break;
                                        case 2: //金额****元（并行 行号为0x82,屏数固定为1）
                                            //第③行
                                            buff[0 + 108] = 0x82;
                                            buff[1 + 108] = 0x01;
                                            buff[2 + 108] = Convert.ToByte(0);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 108] = Convert.ToByte(packet.body["uLedChangeTime3"]);

                                            tmpBytes = Encoding.ASCII.GetBytes(new string(';', 16));    //0x3B 表示空格显示默认填充                                           
                                            tmpBytes.CopyTo(buff, 4 + 108);
                                            buff[4 + 108] = 0x80;   //金(0x0080)
                                            buff[5 + 108] = 0x00;
                                            buff[6 + 108] = 0x80;   //额(0x0180)
                                            buff[7 + 108] = 0x01;
                                            //buff[8 + 108] = 0x3A;   //“:”

                                            byteMsg6 = intCharsToBuff(packet.body["uLedMsg3"].ToString().Trim());

                                            if (byteMsg6.Length == 1)
                                            {
                                                byteMsg6.CopyTo(buff, 9 + 108);
                                                buff[10 + 108] = 0x80;   //元(0x0380) 
                                                buff[11 + 108] = 0x04;
                                            }
                                            else if (byteMsg6.Length == 2)
                                            {
                                                byteMsg6.CopyTo(buff, 8 + 108);
                                                buff[10 + 108] = 0x80;   //元(0x0380) 
                                                buff[11 + 108] = 0x04;
                                            }
                                            else if (byteMsg6.Length == 3)
                                            {
                                                byteMsg6.CopyTo(buff, 9 + 108);
                                            }
                                            else
                                            {
                                                byteMsg6.CopyTo(buff, 8 + 108);
                                            }

                                            //buff[9 + 108 + byteMsg6.Length] = 0x80;   //元(0x0380) 
                                            //buff[10 + 108 + byteMsg6.Length] = 0x04;
                                            break;
                                        case 3: // 余****天（并行 行号为0x82,屏数固定为1）
                                            //第③行
                                            buff[0 + 108] = 0x82;
                                            buff[1 + 108] = 0x01;
                                            buff[2 + 108] = Convert.ToByte(0);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 108] = Convert.ToByte(packet.body["uLedChangeTime3"]);

                                            tmpBytes = Encoding.ASCII.GetBytes(new string(';', 16));    //0x3B 表示空格显示默认填充                                           
                                            tmpBytes.CopyTo(buff, 4 + 108);
                                            buff[4 + 108] = 0x80;   //余(0x0280)
                                            buff[5 + 108] = 0x02;
                                            //buff[6 + 108] = 0x3A;   //“:”

                                            //byteMsg6 = intCharsToBuff(packet.body["uLedMsg3"].ToString().Trim());
                                            //byteMsg6.CopyTo(buff, 6 + 108);
                                            //buff[6 + 108 + byteMsg6.Length] = 0x80;   //天(0x0380) 
                                            //buff[7 + 108 + byteMsg6.Length] = 0x03;

                                            byteMsg6 = intCharsToBuff(packet.body["uLedMsg3"].ToString());
                                            if (byteMsg6.Length < 4)
                                            {
                                                byteMsg6.CopyTo(buff, 7 + 108);
                                                buff[7 + 108 + byteMsg6.Length] = 0x80;   //天(0x0380) 
                                                buff[8 + 108 + byteMsg6.Length] = 0x03;
                                            }
                                            else if (byteMsg6.Length == 4)
                                            {
                                                byteMsg6.CopyTo(buff, 6 + 108);
                                                buff[6 + 108 + byteMsg6.Length] = 0x80;   //天(0x0380)
                                                buff[7 + 108 + byteMsg6.Length] = 0x03;
                                            }
                                            else
                                            {
                                                byteMsg6.CopyTo(buff, 6 + 108);
                                            }

                                            break;
                                        case 4: // 余****元（并行 行号为0x82,屏数固定为1）
                                            //第③行
                                            buff[0 + 108] = 0x82;
                                            buff[1 + 108] = 0x01;
                                            buff[2 + 108] = Convert.ToByte(0);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 108] = Convert.ToByte(packet.body["uLedChangeTime3"]);

                                            tmpBytes = Encoding.ASCII.GetBytes(new string(';', 16));    //0x3B 表示空格显示默认填充 
                                            tmpBytes.CopyTo(buff, 4 + 108);
                                            buff[4 + 108] = 0x80;   //余(0x0280)
                                            buff[5 + 108] = 0x02;
                                            //buff[6 + 108] = 0x3A;   //“:”

                                            //byteMsg6 = intCharsToBuff(packet.body["uLedMsg3"].ToString());
                                            //byteMsg6.CopyTo(buff, 6 + 108);
                                            //buff[6 + 108 + byteMsg6.Length] = 0x80;   //元(0x0480)
                                            //buff[7 + 108 + byteMsg6.Length] = 0x04;

                                            byteMsg6 = intCharsToBuff(packet.body["uLedMsg3"].ToString());
                                            if (byteMsg6.Length < 4)
                                            {
                                                byteMsg6.CopyTo(buff, 7 + 108);
                                                buff[7 + 108 + byteMsg6.Length] = 0x80;   //元(0x0380) 
                                                buff[8 + 108 + byteMsg6.Length] = 0x04;
                                            }
                                            else if (byteMsg6.Length == 4)
                                            {
                                                byteMsg6.CopyTo(buff, 6 + 108);
                                                buff[6 + 108 + byteMsg6.Length] = 0x80;   //元(0x0380) 
                                                buff[7 + 108 + byteMsg6.Length] = 0x04;
                                            }
                                            else
                                            {
                                                byteMsg6.CopyTo(buff, 6 + 108);
                                            }
                                            break;
                                        case 5: // 余位****（并行 行号为0x82,屏数固定为1）
                                            //第③行
                                            buff[0 + 108] = 0x82;
                                            buff[1 + 108] = 0x01;
                                            buff[2 + 108] = Convert.ToByte(0);//特效全部为0-静态多屏切换显示;
                                            buff[3 + 108] = Convert.ToByte(packet.body["uLedChangeTime3"]);

                                            tmpBytes = Encoding.ASCII.GetBytes(new string(';', 16));    //0x3B 表示空格显示默认填充 
                                            tmpBytes.CopyTo(buff, 4 + 108);
                                            buff[4 + 108] = 0x80;   //余(0x0280)
                                            buff[5 + 108] = 0x02;
                                            buff[6 + 108] = 0x80;   //位(0x0580)
                                            buff[7 + 108] = 0x05;
                                            //buff[6 + 108] = 0x3A;   //“:”
                                            byteMsg6 = intCharsToBuff(packet.body["uLedMsg3"].ToString().Trim());

                                            if (byteMsg6.Length <= 3)
                                            {
                                                byteMsg6.CopyTo(buff, 9 + 108);
                                            }
                                            else
                                            {
                                                byteMsg6.CopyTo(buff, 8 + 108);
                                            }
                                            break;
                                    }

                                    packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                                    BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                                    break;
                            }
                        }
                        else
                        {

                        }

                        break;
                    case 0x0034:    //设置语音播报信息
                        hasBody = true;
                        buff = new byte[8];
                        buff[0] = Convert.ToByte(packet.body["byContentType"]);
                        buff[1] = Convert.ToByte(packet.body["byVolume"]);
                        buff[2] = Convert.ToByte(packet.body["byType"]);
                        /* 保留一位 buff[3] */
                        BitConverter.GetBytes(Convert.ToSingle(packet.body["fCharges"])).CopyTo(buff, 4);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                    case 0x0035:    //卡口闸杆控制
                        hasBody = true;
                        buff = new byte[1];
                        buff[0] = Convert.ToByte(packet.body["byControl"]);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);

                        break;
                    case 0x0036:    //设置LED显示屏开关 
                        hasBody = true;
                        buff = new byte[1];
                        buff[0] = Convert.ToByte(packet.body["SwitchOnOff"]);
                        packet.head.uDataLength = Convert.ToUInt32(buff.Length);
                        BitConverter.GetBytes(packet.head.uDataLength).CopyTo(head, 4 * 3);
                        break;
                }
            }
            if (hasBody)
            {
                //有消息体
                result1 = new byte[head.Length + buff.Length];
                head.CopyTo(result1, 0);
                buff.CopyTo(result1, head.Length);
            }
            else
            {
                //无消息体
                result1 = new byte[head.Length];
                head.CopyTo(result1, 0);
            }
            return result1;
        }

        /// <summary>
        /// 整型数值转换成四位ASCII字节数组显示
        /// </summary>
        /// <param name="intChars"></param>
        /// <returns></returns>
        private static byte[] intCharsToBuff(string intChars)
        {
            byte[] resultVal;
            byte[] intBytes;
            int charVal = Convert.ToInt32(intChars);
            int cpyIdx = 0;

            if (intChars.Length > 4)
            {
                resultVal = new byte[4];
                resultVal[0] = 0x39;
                resultVal[1] = 0x39;
                resultVal[2] = 0x39;
                resultVal[3] = 0x39;
            }
            else
            {
                intBytes = Encoding.ASCII.GetBytes(intChars);
                resultVal = new byte[intBytes.Length];
                //cpyIdx = 4 - intBytes.Length;
                //cpyIdx = cpyIdx < 0 ? 0 : cpyIdx;
                intBytes.CopyTo(resultVal, cpyIdx);
            }
            return resultVal;
        }

        private static byte[] floatCharsToBuff(string inVal)
        {
            byte[] resultVal = new byte[4];
            float charVal = Convert.ToSingle(inVal);
            return resultVal;
        }

        /// <summary>填充内容信息到命令数组
        /// 
        /// </summary>
        /// <param name="byteMsg">LED显示内容</param>
        /// <param name="OptIdx">填充起始位</param>
        /// <param name="ShowTime">是否插入时间：0 不填充，1填充</param>
        /// <param name="ShowTimePos">时间插入内容位置：0 内容前，1 内容后 </param>
        /// <param name="ShowTimeFormat">内容格式：0 yy年MM月dd日；1 yy-MM-dd；2 yy/MM/dd；3 yy.MM.dd；4 H时mm分ss秒 (24小时制)；5 HH时mm分ss秒 (12小时制)；6 HH:mm:ss (24小时制)；7 H:mm:ss (12小时制)；</param>
        /// <param name="cmdBuff">命令数组</param>
        /// <returns>内容数据长度</returns>
        private static int SetMessageToBuff(byte[] byteMsg, int OptIdx, int ShowTime, int ShowTimePos, int ShowTimeFormat, ref byte[] cmdBuff)
        {
            int msgLen = byteMsg.Length;
            if (ShowTime != 0)   //显示时间
            {
                byte[] tmpBytes = createCMDDateTime(ShowTimeFormat);
                int timeBytesLen = tmpBytes.Length;
                switch (ShowTimePos)
                {
                    case 0:     //时间在内容前
                        tmpBytes.CopyTo(cmdBuff, OptIdx);
                        if (byteMsg.Length <= (48 - timeBytesLen)) //长度足够
                        {
                            byteMsg.CopyTo(cmdBuff, OptIdx + timeBytesLen);
                            msgLen = byteMsg.Length + timeBytesLen;
                        }
                        else    //超长
                        {
                            byteMsg.Take(48 - timeBytesLen).ToArray().CopyTo(cmdBuff, OptIdx);
                            msgLen = 48;
                        }
                        break;
                    case 1:     //时间在内容后
                        if ((byteMsg.Length + timeBytesLen) <= 48) //长度足够
                        {
                            byteMsg.CopyTo(cmdBuff, OptIdx);
                            tmpBytes.CopyTo(cmdBuff, OptIdx + byteMsg.Length);
                            msgLen = byteMsg.Length + timeBytesLen;
                        }
                        else    //超长
                        {
                            byteMsg.Take(byteMsg.Length - timeBytesLen).ToArray().CopyTo(cmdBuff, OptIdx);
                            tmpBytes.CopyTo(cmdBuff, OptIdx + (byteMsg.Length - timeBytesLen));
                            msgLen = 48;
                        }
                        break;
                }
            }
            else
            {
                if (byteMsg.Length > 48)
                {
                    byteMsg.Take(48).ToArray().CopyTo(cmdBuff, OptIdx);
                    msgLen = 48;
                }
                else
                {
                    byteMsg.CopyTo(cmdBuff, OptIdx);
                    msgLen = byteMsg.Length;
                }
            }
            return msgLen;
        }

        public static InfoPacket ByteToModel(byte[] data)
        {
            return new InfoPacket();
        }

        private struct BroadcastEditIPS
        {
            public uint uIpv4Addr { get; set; }

            public uint uIpv4Dns { get; set; }

            public uint uIpv4Gateway { get; set; }

            public uint uIpv4Mask { get; set; }

            public string byMac { get; set; }
        }
    }


}
public class ProtocolHead
{
    private uint phVersion = 0xbbff6bb6;
    public uint uVersion
    {
        get
        {
            return phVersion;
        }
        set
        {
            phVersion = value;
        }
    }

    private uint phCommandID = 0x6005;
    public uint uCommandID
    {
        get
        {
            return phCommandID;
        }
        set
        {
            phCommandID = value;
        }
    }

    private uint phSessionID = 999;
    public uint uSessionID
    {
        get
        {
            return phSessionID;
        }
        set
        {
            phSessionID = value;
        }
    }

    private uint phDataLength = 0;
    public uint uDataLength
    {
        get
        {
            return phDataLength;
        }
        set
        {
            phDataLength = value;
        }
    }

    private uint phErrorCode = 0;
    public uint uErrorCode
    {
        get
        {
            return phErrorCode;
        }
        set
        {
            phErrorCode = value;
        }
    }

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
    private string phReserved = string.Empty;

    public string szReserved
    {
        get
        {
            return phReserved.Substring(0, phReserved.Length > 8 ? 8 : phReserved.Length);
        }
        set
        {
            phReserved = value;
        }
    }

    private uint phCheckSum = 3014706608;
    public uint uCheckSum
    {
        get
        {
            return phCheckSum;
        }
        set
        {
            phCheckSum = value;
        }
    }


}
